﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Admin_Web_test.Models;
using Microsoft.AspNetCore.Mvc;

namespace Admin_Web_test.Controllers
{
    public class HomeConfigController : Controller
    {
        private readonly Common.DBHelp.MySqlContext _context;

        public HomeConfigController(Common.DBHelp.MySqlContext context)
        {
            //https://www.cnblogs.com/yaopengfei/p/12194230.html   5.6
            context.ChangeTracker.QueryTrackingBehavior = Microsoft.EntityFrameworkCore.QueryTrackingBehavior.NoTracking;
            //关闭状态同步
            context.ChangeTracker.AutoDetectChangesEnabled = false;
            //开启：context.ChangeTracker.DetectChanges();
            _context = context;
        }
        public IActionResult Benner()
        {
            return View();
        }
        public JsonResult BannerList(int flag=-1)
        {
            var json = new JsonResultM();
            if (flag == 0 || flag == 1) json.data = _context.HomeBanner.Where(m => m.State == flag).ToList();
            else json.data = _context.HomeBanner.ToList();
            json.success = true;
            return Json(json);
        }
    }
}